import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

let app: ReturnType<typeof createApp> | null = null;

function render(props: any = {}) {
	const { container } = props;
	const target = container ? container.querySelector('#app') : '#app';
	app = createApp(App);
	app.mount(target);
}
renderWithQiankun({
	mount(props) {
		console.log('[child-vue-app] mount', props);
		render(props);
	},
	bootstrap() {
		console.log('[child-vue-app] bootstrap');
	},
	unmount(props) {
		console.log('[child-vue-app] unmount', props);
		if (app) {
			app.unmount();
			app = null;
		}
	},
	update(props) {
		console.log('[child-vue-app] update', props);
	},
});
// 独立运行时
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
	render();
}